
#include "common.hpp"

int main()
{
    umask(0);
    int n = mkfifo(FifoName, 0666);
    if (n < 0)
        ERR_EXIT("mkfifo");
    else
        std::cout << "mkfifo success" << std::endl;

    int infd = open(FileName, O_RDONLY);
    if (infd < 0)
        ERR_EXIT("open");
    else
        std::cout << "open file success" << std::endl;

    int outfd = open(FifoName, O_WRONLY);
    if (outfd < 0)
        ERR_EXIT("open");
    else
        std::cout << "open fifo success" << std::endl;

    char buffer[1024];
    while(int n = read(infd,buffer,sizeof(buffer)-1))
    {
        write(outfd,buffer,n);
    }
    close(infd);
    close(outfd);
    unlink(FifoName);
    return 0;
}